-- @owner: @nanyang12
-- @date: 2024/10/23
-- @testpoint:表使用type做字段名,使用该字段创建触发器

--step1:建表 
drop table if exists t_ddl_type_0048; 
create table t_ddl_type_0048(name varchar(128), type varchar(128), definition varchar(2048), organization varchar(128), id integer not null constraint st_csyssys_pk primary key, description varchar(256)); 
--step2:创建触发器函数 
create or replace function f_ddl_type_0048() returns trigger 
security definer 
as $$ 
begin
    new.type :='geographic'; 
    return new; 
end;
$$ language plpgsql;
/
--step3:创建触发器 
drop trigger if exists tr_ddl_type_0048 on t_ddl_type_0048; 
create trigger tr_ddl_type_0048 before update on t_ddl_type_0048 for each row execute procedure f_ddl_type_0048();
/
--step4:向表插入数据,查询数据 
insert into t_ddl_type_0048(type,id) values('update_before',1); 
update t_ddl_type_0048 set type='update_after'; 
select type from t_ddl_type_0048; 
--step5:清理环境 
drop trigger if exists tr_ddl_type_0048 on t_ddl_type_0048; 
drop function if exists f_ddl_type_0048; 
drop table if exists t_ddl_type_0048 cascade;
